package com.cci.kangdao.utilTool;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import com.cci.kangdao.service.impl.SMSEnum;

public class ResultTemplate {
	
	/**
	 * 成功返回数据
	 * @param status
	 * @param msg
	 * @param data
	 * @param functions
	 * @return
	 */
	public static String successResult(int status,String msg,List<Map<String,Object>> functions){

		JSONObject obj = new JSONObject();
		JSONObject jb = new JSONObject();
		try {
			jb.put("functions", functions);
			obj.put("status", status);
			obj.put("msg", msg);
			obj.put("data", jb);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return obj.toString();
	}
	
	
	public static String successResult(int status,String msg,Map<String,Object> functions){

		JSONObject obj = new JSONObject();
		JSONObject jb = new JSONObject();
		try {
			jb.put("functions", functions);
			obj.put("status", status);
			obj.put("msg", msg);
			obj.put("data", jb);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return obj.toString();
	}
	
	
	public static String successResultNull(){

		JSONObject obj = new JSONObject();
		JSONObject jb = new JSONObject();
		try {
			jb.put("functions", "");
			obj.put("status", -18);
			obj.put("msg", ApiErrorCode.getInstance().getErrorMsg(-18));
			obj.put("data", jb);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return obj.toString();
	}
	
	public static void main(String[] args) {
		Map<String,Object> map = new HashMap<>();
		map.put("aa", "z1");
		map.put("bb", "z2");
		
		List<Map<String,Object>> list = new ArrayList<>();

		Map<String,Object> map2 = new HashMap<>();
		map2.put("aa", "z1");
		map2.put("bb", "z2");
		list.add(map2);

		Map<String,Object> map3 = new HashMap<>();
		map3.put("aa", "z1");
		map3.put("bb", "z2");
		list.add(map3);
		
		Map<String,Object> map4 = new HashMap<>();
		map4.put("stationInfo",map);
		map4.put("hisData",list);
		
//		System.out.println(successResultSS( map4));

//		System.out.println(successResult( 1,"dd",list));
	}
}
